<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>无标题文档</title>
    <link href="erzu/css/style.css" rel="stylesheet" type="text/css"/>

    <script src="../vue.min.js"></script>
    <script src="../axios.min.js"></script>

    <script type="text/javascript" src="erzu/js/jquery.js"></script>
    <script language="javascript">
        $(function () {
            //导航切换
            $(".imglist li").click(function () {
                $(".imglist li.selected").removeClass("selected")
                $(this).addClass("selected");
            })
        })
    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            $(".click").click(function () {
                $(".tip").fadeIn(200);
            });

            $(".tiptop a").click(function () {
                $(".tip").fadeOut(200);
            });

            $(".sure").click(function () {
                $(".tip").fadeOut(100);
            });

            $(".cancel").click(function () {
                $(".tip").fadeOut(100);
            });

        });
    </script>
</head>


<body>

<!-- <div class="place">
    <span>位置：</span>
    <ul class="placeul">
        <li><a href="#">首页</a></li>
        <li><a href="imglist.html">管理员页面</a></li>

    </ul>
</div> -->
<div id="app">
    <!--<br>
        <a href="log.html?role_id=3" class="ibtn">查看BI工作记录</a>
        <a href="log.html?role_id=2" class="ibtn">查看DBI工作记录</a>

    <br>
    <br>-->

    <div class="leftinfo">
        <div class="listtitle">用户列表</div>
		<input type="button" class="ibtn" value="用户新增" @click="newUser()"/>
        <table class="imgtable">
            <tr>
                <!-- <td></td> -->
                <td>用户编号</td>
                <td>用户姓名</td>
                <td>最后登陆时间</td>
                <td>用户状态</td>
                <td>用户权限</td>
                <td>操作权限</td>
                <td>操作状态</td>

            </tr>
            <tr v-for="item in historyList">
                <!-- <td><input name="" type="checkbox" value=""/></td> -->
                <td>{{item.userid}}</td>
                <td>{{item.username}}</td>
                <td>{{item.lastLogin}}</td>
                <td v-if="item.status=='CAN_USE'">可用</td>
                <td v-if="item.status=='CAN_NOT_USE'">禁用</td>
                <td>{{item.roles}}</td>
                <td>
                    <p v-if="item.roles=='ADMIN'">至高无上的权利</p>
                    <input type="button" class="ibtn" v-if="item.roles=='BI'||item.roles=='VISITOR'" value="更改为DBA"
                           @click="audit(item.id,'2','DBA')"/>
                    <input type="button" class="ibtn" v-if="item.roles=='DBA'||item.roles=='VISITOR'" value="更改为BI"
                           @click="audit(item.id,'3','BI')"/>
                </td>
                <td>
                    <p v-if="item.roles=='ADMIN'">至高无上,不可禁用</p>
                    <input type="button" class="ibtn" v-if="item.status=='CAN_USE'&&item.roles!='ADMIN'" value="禁用"
                           @click="forbidden(item.id)"/>
                    <!-- <input type="button"  class="ibtn" v-if="item.status=='CAN_NOT_USE'&&item.roles!='ADMIN'" value="可用" @click="audit(item.id,0)"/> -->
                </td>
            </tr>
        </table>
    </div>
</div>

<!--<div class="pagin">-->
<!--    <div class="message">共<i class="blue">10</i>条记录，当前显示第&nbsp;<i class="blue">1&nbsp;</i>页</div>-->
<!--    <ul class="paginList">-->
<!--        <li class="paginItem"><a href="javascript:;"><span class="pagepre"></span></a></li>-->
<!--        <li class="paginItem current"><a href="javascript:;">1</a></li>-->
<!--        <li class="paginItem"><a href="javascript:;">2</a></li>-->
<!--        <li class="paginItem"><a href="javascript:;">3</a></li>-->
<!--        <li class="paginItem"><a href="javascript:;">4</a></li>-->
<!--        <li class="paginItem"><a href="javascript:;">5</a></li>-->
<!--        <li class="paginItem more"><a href="javascript:;">...</a></li>-->
<!--        <li class="paginItem"><a href="javascript:;">10</a></li>-->
<!--        <li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>-->
<!--    </ul>-->
<!--</div>-->


<script type="text/javascript">
    $('.imgtable tbody tr:odd').addClass('odd');
</script>
</body>
<script>
    new Vue({
        el: "#app",
        data: {
            historyList: [],
            user: {
                id: '',
                roleid: '',
                roles: ''
            }
        },
        created: function () {
            this.gethistoryList();
        },
        methods: {
            gethistoryList: function () {
                var Authorization = localStorage.getItem('Authorization');
                _this = this;
                axios.get("http://localhost:9005/admin/adminController/findAllUser", {headers: {'Authorization': Authorization}}).then(function (result) {
                    _this.historyList = result.data.data;
                }).catch(function (error) {
                  if (5102 == error.response.status) {

                      alert("无权限");
                      location.href="wuquan.html";
                      
                  }
              })
            },
            audit: function (id, roleid, roles) {
                var Authorization = localStorage.getItem('Authorization');
                this.user.id = id;
                this.user.roleid = roleid;
                this.user.roles = roles;
                axios.post("http://localhost:9005/admin/adminController/updateUser", this.user, {headers: {'Authorization': Authorization}}).then(function (result) {
                    if (result.data.flag) {
                        alert(result.data.message);
                        location.href = "user.html";
                    }
                })
            },
            forbidden: function (id) {
                var Authorization = localStorage.getItem('Authorization');
                axios.get("http://localhost:9005/admin/adminController/deleteUserById/" + id, {headers: {'Authorization': Authorization}}).then(function (result) {
                    if (result.data.flag) {
                        alert(result.data.message);
                        location.href = "user.html";
                    }
                })
            },
			newUser: function(){
				location.href = "newUser.html";
			}
        }
    })
</script>
</html>
